{extend name="base"}
{block name="title"}亲友团绑定管理{/block}
{block name="head"}
<style>
.border-table tbody th{text-align:center; color:#333; font-weight:400; padding-left:5px;}
.border-table{font-size:12px; color:#666;}
.border-table th, .border-table td{padding:0 4px;}
</style>
{/block}
{block name="body"}
<body class="mainbody">
<form>
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>亲友团绑定管理</span>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">
  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"><i class="iconfont icon-more"></i></a>
      <div class="l-list">
        <div class="menu-list">
          <div class="rule-single-select">
            <select name="channel" style="display:none">
              <option value="-1">===所有渠道===</option>
              {volist name="CHANNELS" id="val"}
              <option value="{$key}"{eq name="channel" value="$key"} selected{/eq}>[{$key}]{$val.Name}</option>
              {/volist}
            </select>
          </div>
          <div class="rule-single-select">
            <select name="kind" style="display:none">
              <option value="-1">===所有游戏===</option>
              {volist name="GAME_KIND" id="val"}
              <option value="{$key}"{eq name="kind" value="$key"} selected{/eq}>[{$key}]{$val}</option>
              {/volist}
            </select>
          </div>
          <div class="rule-single-select">
            <select name="FamilyType" style="display:none">
              <option value="-1">===所有类型===</option>
              {volist name="FamilyType" id="val"}
              <option value="{$key}"{eq name="FamilyType" value="$key"} selected{/eq}>[{$key}]{$val}</option>
              {/volist}
            </select>
          </div>
          <input type="text" class="input txt" autocomplete="off" name="search" value="{$search|default=''|htmlentities}" placeholder="六位群号/群主GameID/群主UserID" />
          <a class="btn-search"><i class="iconfont icon-search"></i></a>
        </div>
      </div>
      <div class="r-list">
        <input type="text" style="min-height: 25px;" id="KindID" placeholder="新增游戏KindID">
        <a class = "input" id="updated" href="javascript:;">更新房间</a>
        <a class="input" id="new">新建区间</a>
        <!-- <a class="input" id="clear">清除所有</a> -->
      </div>
    </div>
  </div>
</div>
<!--/工具栏-->

<!--列表-->
<div class="table-container">
<table class="border-table ltable">
  <tr>
    <th>#</th>
    <th>渠道</th>
    <th>游戏</th>
    <th>群号</th>
    <th>群标题</th>
    <th>群主</th>
    <th>成员数</th>
    <th>黑名单</th>
    <th>上限分数</th>
    <th>下限分数</th>
    <th>审核状态</th>
    <th>创建时间/更新时间</th>
    <th>操作</th>
  </tr>
  {empty name="list"}
  <tr><td colspan="13">Oh~暂无数据!</td></tr>
{else}
  {volist name="list" id="v"}
  <tr data-auid="{$v.AUID}" data-code="{$v.Code}" data-caption="{$v.Caption}" data-id="{$v.ID}">
    <td>{$v.ROW_NUMBER}</td>
    <td>[{$v.Channel}]{$CHANNELS[$v.Channel]['Name'] ?? '--'}</td>
    {if condition="$v.FamilyType eq 1"}
    <td>[房卡场].[{$v.KindID}]{$GAME_KIND[$v.KindID] ?? '--'} </td>
    {elseif condition="$v.FamilyType eq 2"/}
    <td><span style="color: blue;">[金币场]</span>.[{$v.KindID}]{$GAME_KIND[$v.KindID] ?? '--'} </td>
    {else/}
    <td>[{$v.KindID}]{$GAME_KIND[$v.KindID] ?? '--'}</td>
    {/if}
    <td><a target="_blank" href="{:url('family')}?code1={$v.Code}">{$v.Code}</a></td>
    <td>{$v.Caption}</td>
    <td class="user-avatar">
      <a target="_blank" href="{:url('user.detail/index')}?UserID={$v.AUID}">
        <img src="{$v.HeadImgUrl?:'__STATIC__/houtai/images/dface.png'}" />
      </a>
      <div class="user-box">
        <h4><a target="_blank" class="at_{$v.AccountsType}" href="{:url('user.detail/index')}?UserID={$v.AUID}">{:htmlentities($v.NickName)}</a></h4>
        <i>{$v.GameID}</i>
      </div>
    </td>
    <td><a target="_blank" href="{:url('index')}?code1={$v.Code}">{$v.TotalMem*1}</a></td>
    <td><a target="_blank" href="{:url('index')}?code1={$v.Code}&black=1">{$v.TotalBlack*1}</a></td>
    <td>{$RangeScore[$v.Code]['MaxScore'] ?? 0}</td>
    <td>{$RangeScore[$v.Code]['MinScore'] ?? 0}</td>
    <td class="fst_{$v.State}">[{$v.State}]{$STATES[$v.State] ?? '--'}</td>
    <td>{$v.CreateTime}<br/>{$v.UpdateTime}</td>
    <td>
    {eq name="v.State" value="0"}
      <input class="a" type="button" value="确认审核" />
    {else/}
      <input class="b" type="button" value="添加成员" />
      <input class="d" type="button" value="修改区间" /><br/>
      <input class="c" type="button" value="修改标题" />
      <input class="e" type="button" value="删除区间" />
    {/eq}
    </td>
  </tr>
  {/volist}
{/empty}
</table>
</div>
<!--/列表-->

<!--内容底部-->
<div class="page-footer"><div class="btn-wrap">{$list->render()}</div></div>
<!--/内容底部-->

</form>
<script>
$(function () {

  $('input.a').click(function () {  // 确认审核
    var tr = $(this).parents('tr');
    var id = tr.data('id');
    dialog({
      title: '提示',
      content: '是否确认申请?',
      okValue: '确定',
      ok: function () {
        $.post("{:url('agree')}?id=" + id, function (resp, text, xhr) {
          console.log(resp);
          if (resp.errno == 0) {
            location.reload();
          } else {
            alert(resp.error);
          }
        });
        return false;
      },
      cancelValue: '取消',
      cancel: function () {}
    }).showModal();
  });
  
  $('input.b').click(function () {  // 添加成员
    var _this = $(this);
    var tr = _this.parents('tr');
    var code = tr.data('code');
    var id = tr.data('id');
    dialog({
      title: '添加亲友团[' + code + ']成员',
      content: '<input type="text" class="input" placeholder="请输入GameID" />',
      okValue: '确定',
      cancelValue: '取消',
      cancel: function () {},
      ok: function () {
        var a = $(this.node);
        var p = $('.input', a);
        var GameID = p.val();
        $.post("{:url('MemberAdd')}", {
          FamilyID: id,
          GameID: GameID
        }, function (resp, text, xhr) {
          console.log(resp);
          if (resp.errno == 0) {
            location.reload();
            alert('添加成功');
          } else {
            alert(resp.error);
          }
        });
        return false;
      }
    }).showModal();
  });
  
  $('input.c').click(function () {  // 修改标题
    var _this = $(this);
    var tr = _this.parents('tr');
    var code = tr.data('code');
    var caption = tr.data('caption');
    var id = tr.data('id');
    dialog({
      title: '修改亲友团[' + code + ']标题',
      content: '<input type="text" class="input" placeholder="请输入亲友团标题" value="' + caption + '" />',
      okValue: '确定',
      cancelValue: '取消',
      cancel: function () {},
      ok: function () {
        var a = $(this.node);
        var p = $('.input', a);
        var caption = p.val();
        $.post("{:url('UpdateCaption')}", {
          FamilyID: id,
          Caption: caption
        }, function (resp, text, xhr) {
          console.log(resp);
          if (resp.errno == 0) {
            location.reload();
          } else {
            alert(resp.error);
          }
        });
        return false;
      }
    }).showModal();
  });


  $('.toolbar a#updated').click(function(){  //更新游戏房间
    var kind = $('#KindID').val();
    dialog({
      title: '更新亲友团',
      content: '<select name="familycode" style="">\n' +
              '<option value="">===选择类型===</option>\n' +
              '<option value="1" name="familycode" id="optt" >房卡区</option>\n' +
              '<option value="2" name="familycode" id="optt" >金币区</option>\n' +
              '</select>',
      okValue: '确定',
      cancelValue: '取消',
      cancel: function () {},
      ok: function () {
        var p = $('[id="optt"]:selected').val();
        console.log(p);
        console.log(kind);
        $.post("{:url('user.family.range/updateRoom')}", {
          FamilyType:p,
          KindID:kind,
        }, function (resp, text, xhr) {
          console.log(resp);
          if (resp.errno == 0) {
            alert(resp.error);
            location.reload();
          } else {
            alert(resp.error);
            location.reload();
          }
        });
        return false;
      }
    }).showModal();
  });



  $.FamilyControl.init({
    URL_DETAIL: "{:url('user.family.range/detail')}",
    URL_DELONE: "{:url('user.family.range/delone')}",

  });
  $('.toolbar a#new').click(function () { // 新建
    $.FamilyControl.ShowDetailDialog(0);
  });
  $('.toolbar a#clear').click(function () { // 删除所有区间
    var sel = $('select[name=channel]').val();
    $.FamilyControl.ShowDelallConfirm(sel);
  });
  $('input.d').click(function () {  // 修改区间
    var GroupID = $(this).parents('tr').data('code');
    $.FamilyControl.ShowDetailDialog(GroupID);
  });
  $('input.e').click(function () {  // 删除区间
    var GroupID = $(this).parents('tr').data('code');
    $.FamilyControl.ShowDeloneConfirm(GroupID);
  });
  
});
</script>
</body>
{/block}